package cn.doitedu;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class HbaseClientDemo {

    public static void main(String[] args) throws IOException {

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","doitedu:2181,doitedu2:2181,doitedu3:2181");

        // 创建连接
        Connection connection = ConnectionFactory.createConnection(conf);


        // 获取表对象
        Table table = connection.getTable(TableName.valueOf("stu_info"));


        // 构造一个get查询的参数对象
        Get get = new Get(Bytes.toBytes("aaa"));
        // 指定查询要返回的列
        get.addColumn(Bytes.toBytes("f1"),Bytes.toBytes("name"));
        get.addColumn(Bytes.toBytes("f1"),Bytes.toBytes("age"));

        // 调用表上的get方法进行get查询
        Result result = table.get(get);

        byte[] valueBytes = result.getValue(Bytes.toBytes("f1"), Bytes.toBytes("name"));


        System.out.println(Bytes.toString(valueBytes));



        table.close();
        connection.close();


    }


}
